<?php

use Illuminate\Database\Seeder;

class ConfigSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return mixed
     */
    public function run()
    {
        return $this->insert([
            [
                'type' => 0,
                'name' => '短信通道',
                'key' => 'sms',
                'value' => '',
                'params' => [
                    'tpl' => [
                        'captcha' => ''
                    ],
                    'appid' => '',
                    'signature' => '',
                    'access_ak' => '',
                    'access_sk' => ''
                ]
            ],
            [
                'type' => 0,
                'name' => '微信小程序',
                'key' => 'wechat_xcx',
                'value' => '',
                'params' => [
                    'secret' => ''
                ]
            ],
            [
                'type' => 0,
                'name' => '微信公众号',
                'key' => 'wechat_gzh',
                'value' => '',
                'params' => [
                    'secret' => ''
                ]
            ]
        ]);
    }

    /**
     * 插入数据
     *
     * @param array $params
     * @return bool
     */
    public function insert(array $params) {
        foreach ($params as &$item) {
            if (isset($item['params']) && $item['params']) {
                $item['params'] = json_encode($item['params'], JSON_UNESCAPED_UNICODE);
            } else {
                $item['params'] = null;
            }
        }
        return DB::table('configs')->insert($params);
    }
}
